#include "game_window.h"

Game_window::Game_window():
    m_Width(0),
    m_Height(0),
    m_Bpp(0),
    m_Fullscreen(false)
{

}

Game_window::~Game_window()
{
    SDL_Quit();
}

bool Game_window::create_game_window(int width, int height, int bpp, bool fullscreen, const string& title)
{
    if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER ) != 0 )
		{
			return false;
		}

		//all values are "at least"!
		SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
		SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
		SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
		SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 5);
		SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
		SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

		// Set the title.
		SDL_WM_SetCaption(title.c_str(), title.c_str());

		// Flags tell SDL about the type of window we are creating.
		int flags = SDL_OPENGL | SDL_DOUBLEBUF | SDL_HWSURFACE;

		if(fullscreen == true)
		{
			flags |= SDL_FULLSCREEN;
		}

		if(SDL_VideoModeOK(width, height, bpp, flags) != 0)
		{
		    // Create the window
            screen = SDL_SetVideoMode( width, height, bpp, flags );
		}
        else
        {
            return false;
        }

        //Copy the values incase we need them
		m_Height = screen->h;
		m_Width = screen->w;
		m_Title = title;
		m_Fullscreen = fullscreen;
		m_Bpp = bpp;

		//Hide mouse!!
		SDL_ShowCursor(SDL_DISABLE);

		return true;
}

void Game_window::setSize(int width, int height)
{
    m_Height = height;
	m_Width = width;
}

int Game_window::getHeight()
{
    return m_Height;
}
int Game_window::getWidth()
{
    return m_Width;
}
